package com.atguigu.springcloud.contrlller;

import com.atguigu.springcloud.serivces.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: shikong
 * @Date: 2020/8/4 15:02
 */

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystirxController {

    @Resource
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/paymenok/{id}")
    public String paymentInfo_OK(@PathVariable(value = "id") Integer id){

        log.info("paymentInfo_OK={}",id);
        return paymentHystrixService.paymentInfo_OK(id);
    }
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    //@HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_Fallback",commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="2000")})
    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable(value = "id") Integer id){

        log.info("paymentInfo_TimeOut={}",id);
       // int i = 10 / 0;
        return paymentHystrixService.paymentInfo_TimeOut(id);
    }

    public String paymentInfo_TimeOut_Fallback(Integer id){

        log.info("订单线程池：{}",Thread.currentThread().getName(),"paymentInfo_TimeOut,id{}",id ,"服务降级方法");
        return  "订单线程池："+Thread.currentThread().getName()+" paymentInfo_TimeOut,id"+id+" :服务降级方法";

    }


    public String payment_Global_FallbackMethod(){

        return "Global异常处理信息请稍后再试";
    }

}
